<?php 
session_start(); 
?>
<?php
include("config/config.php");
$Malaptop = $_GET["Malaptop"];
$kt = 0;
for($i = 1; $i <= $_SESSION["tongsp"];$i++)
{
	if($_GET["Malaptop"]==$_SESSION["Malaptop".$i])
	{
		$_SESSION["Soluong".$i]++;
		?>
        <script>
        location.href="index.php?act=gh";
        </script>
        <?php
		$kt = 1;
		break;		
	}
}
if($kt == 0)
{
	$lenh = "select * from laptop where Malaptop='$Malaptop'";
	$kq = mysql_query($lenh);
	$n = mysql_num_rows($kq);
	if($n > 0)
	{
		$row = mysql_fetch_array($kq);
		$_SESSION["tongsp"]++;
		$j = $_SESSION["tongsp"];
		session_register("Malaptop".$j);
		$_SESSION["Malaptop".$j]=$row[Malaptop];
		session_register("Tenlaptop".$j);
		$_SESSION["Tenlaptop".$j]=$row[Tenlaptop];
		session_register("Dongia".$j);
		$_SESSION["Dongia".$j]=$row[Dongia];
		session_register("Soluong".$j);
		$_SESSION["Soluong".$j]=1;	
		?>
        <script>
        location.href="index.php?act=gh";
        </script>
        <?php	
	}	
}

?>
<form id="form1" name="form1" method="post" action="">
  <table width="900" border="1" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFF99" bordercolor="#FF99CC" style="border-collapse:collapse">
    <tr>
      <td colspan="5" align="center" bgcolor="#FFFF66"><p>&nbsp;</p>
        <p><strong>DANH SÁCH  HÀNG</strong><strong> ĐÃ ĐẶT</strong></p>
        <p>Các mặt hàng bạn đã chọn vào giỏ hàng</p>
      <p>&nbsp;</p></td>
    </tr>
    <tr>
      <td align="center">STT</td>
      <td align="center">Tên laptop</td>
      <td align="center">Đơn giá</td>
      <td align="center">Số lượng</td>
      <td align="center">Thành tiền</td>
    </tr>
    <?php
	for($i = 1; $i <= $_SESSION["tongsp"]; $i++)
	{
		?>
    <tr>
      <td align="center"><?php  echo $i;  ?></td>
      <td align="center"><?php  echo $_SESSION["Tenlaptop".$i]  ?></td>
      <td align="center"><?php  echo $_SESSION["Dongia".$i]  ?></td>
      <td align="center"><label for="soluong"></label>
      <input name="C<?php  echo $i  ?>" type="text" id="soluong" size="10" value="<?php  echo $_SESSION["Soluong".$i];  ?>" readonly="readonly" /></td>
      <td align="center"><?php  echo $_SESSION["Soluong".$i]*$_SESSION["Dongia".$i]  ?></td>
    </tr>
    <?php
	}
	?>
  </table>
  <?php
  function tongtien()
  {
	  $s = 0;
	  for($i = 1; $i <= $_SESSION["tongsp"];$i++)
	  {
		  
		$s = $s + $_SESSION["Soluong".$i]*$_SESSION["Dongia".$i];
		 
	  }
	  return $s; 
  }
  
  ?>
  <p align="center">Tổng tiền: <b><font color="#FF0000"><?php echo number_format(tongtien(),0,',','.');    ?> VNĐ</font></b></p>
 
</form>
<p align="center">
    	<form method="post" action="https://www.nganluong.vn/advance_payment.php"><input type=hidden name=receiver value="anhphuoc73@gmail.com" /><input type=hidden name=product value="<? echo $_GET['idDH']; ?>" /><input type=hidden name=price value="<? echo tongtien(); ?>" /><input type=hidden name=return_url value="act=thanhtoanthanhcong" /><input type=hidden name=comments value="<!--Ghi chú về đơn hàng-->" /><center>
    	  <p>
    	    <input type=image src="https://www.nganluong.vn/data/images/buttons/3.gif" />
    	  </p>
    	  <p><a onclick="history.back(-1)">Back</a></p>
    	</center></form>

</p>
